plot_smooths(
model = gam_egg_dev,
series = Elevation,
comparison = Species,
facet_terms = Loc_type,
)
plot_smooths(
model = gam_egg_dev,
series = Elevation,
comparison = Species,
facet_terms = Loc_type,
) +
theme_bw()
plot_smooths(
model = gam_egg_dev,
series = Elevation,
comparison = Species,
facet_terms = Loc_type,
) +
theme_bw()+
theme(legend.position = "top")
plot_smooths(
model = gam_egg_dev,
series = Elevation,
comparison = Loc_type,
facet_terms = Species,
) +
theme_bw()+
theme(legend.position = "top")
gam_egg_dev <- gam(egg_dev ~ s(Elevation, by = c(Species, Loc_type)) + Species + Loc_type , data = res_ecto_stats, method = "REML")
gam_egg_dev <- gam(egg_dev ~ s(Elevation, by = Species) + Species + Loc_type , data = res_ecto_stats, method = "REML")
summary(gam_egg_dev)
plot(gam_egg_dev, residuals = TRUE, pch=1)
plot_smooths(
model = gam_egg_dev,
series = Elevation,
comparison = Loc_type,
facet_terms = Species,
) +
theme_bw()+
theme(legend.position = "top")
gam_egg_dev <- gam(Lifespan ~ s(Elevation, by = Species) + Species + Loc_type , data = res_ecto_stats, method = "REML")
gam_egg_dev <- gam(LifeSpan ~ s(Elevation, by = Species) + Species + Loc_type , data = res_ecto_stats, method = "REML")
summary(gam_egg_dev)
plot(gam_egg_dev, residuals = TRUE, pch=1)
plot_smooths(
model = gam_egg_dev,
series = Elevation,
comparison = Loc_type,
facet_terms = Species,
) +
theme_bw()+
theme(legend.position = "top")
rm(list = ls())
using<-function(...) {
libs<-unlist(list(...))
req<-unlist(lapply(libs,require,character.only=TRUE))
need<-libs[req==FALSE]
if(length(need)>0){
install.packages(need)
lapply(need,require,character.only=TRUE)
}
}
using("NicheMapR", "microclima", "raster", "ggplot2", "tidyverse", "matlab", "R.matlab")
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(message=FALSE)
knitr::opts_chunk$set(warning=FALSE)
knitr::opts_chunk$set(tidy=TRUE)
using<-function(...) {
libs<-unlist(list(...))
req<-unlist(lapply(libs,require,character.only=TRUE))
need<-libs[req==FALSE]
if(length(need)>0){
install.packages(need)
lapply(need,require,character.only=TRUE)
}
}
using("dplyr", "ggplot2", "ggpubr", "rstatix", "NCmisc", "car", "lme4", "DHARMa", "emmeans", "performance", "sjPlot", "rphylopic", "jpeg", "flexplot", "report", "broom", "ggfortify", "MASS", "jtools", "svglite",  "multcomp", "vegan", "showtext", "formatR")
rm(list = ls())
getwd()
load("../../Results/ECTOTHERM_results/results_all_ecto2.Rda")
res_ecto_stats <- results_all
#Get yearly values
res_ecto_stats$Forage_year <- res_ecto_stats$Forage/res_ecto_stats$Year
res_ecto_stats$Bask_year <- res_ecto_stats$Bask/res_ecto_stats$Year
res_ecto_stats$Fecundity_year <- res_ecto_stats$Fecundity/res_ecto_stats$Year
res_ecto_stats$Clutches_year <- res_ecto_stats$Clutches/res_ecto_stats$Year
#Rename values
res_ecto_stats$Species[res_ecto_stats$Species == "Ihor"] <- "I. horvathi"
res_ecto_stats$Species[res_ecto_stats$Species == "Pmur"] <- "P. muralis"
res_ecto_stats$Sintopy[res_ecto_stats$Sintopy == "sint"] <- "Sintopy"
res_ecto_stats$Sintopy[res_ecto_stats$Sintopy == "aloPmur"] <- "Muralis allotopy"
res_ecto_stats$Sintopy[res_ecto_stats$Sintopy == "aloIhor"] <- "Horvathi allotopy"
#Turn to factor
res_ecto_stats$Locality <- as.factor(res_ecto_stats$Locality)
res_ecto_stats$Sintopy <- as.factor(res_ecto_stats$Sintopy)
res_ecto_stats$Species <- as.factor(res_ecto_stats$Species)
str(res_ecto_stats)
res_ecto_stats <- res_ecto_stats %>%
rename(Loc_type = Sintopy)
res_ecto_stats <- res_ecto_stats[, c( "Elevation", "Loc_type", "Species", "MeanTALOC", "MeanRHLOC", "Solar", "NO_Snow", "egg_dev", "LifeSpan",
"Years_repro", "Bask_year", "Forage_year", "Fecundity_year")]
head(res_ecto_stats)
str(res_ecto_stats)
## Microclimate analysis table
loc_stats <- res_ecto_stats %>% distinct(MeanTALOC, .keep_all = TRUE)
#check data distribution
gghistogram(loc_stats$MeanTALOC, bins = 15)
ggboxplot(loc_stats$MeanTALOC)
#Check lm model
lm_MeanTALOC <- lm(MeanTALOC ~Elevation+Loc_type, data = loc_stats)
# Get summary and p values
summary(lm_MeanTALOC)
# Plot
lm_Plot_eTemp <- lm(MeanTALOC ~Elevation, data = loc_stats)
MeanTemp_plot <- visualize(lm_Plot_eTemp,  MeanTALOC ~Elevation, plot="model")+
scale_color_manual(values = c("black"))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Mean temperature (°C)")), x=NULL)+
theme(legend.position="null")
MeanTemp_plot
#Check model fit, residuals etc.
autoplot(lm_MeanTALOC)+
theme_classic()
shapiro.test(residuals(lm_MeanTALOC))
#check data distribution
gghistogram(loc_stats$MeanRHLOC, bins = 15)
ggboxplot(loc_stats$MeanRHLOC)
#Check lm model first
lm_MeanRHLOC <- lm(MeanRHLOC ~Elevation+Loc_type, data = loc_stats)
# Get summary and p values
summary(lm_MeanRHLOC)
# Plot
lm_plot_eHum <- lm(MeanRHLOC ~Elevation, data = loc_stats)
Mean_humid <- visualize(lm_plot_eHum, MeanRHLOC ~ Elevation, plot="model")+
scale_color_manual(values = c("black"))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Mean relative humidity (%)")), x=NULL)+
theme(legend.position="null")
Mean_humid
#Check model fit, residuals etc.
autoplot(lm_MeanRHLOC)+
theme_classic()
shapiro.test(residuals(lm_MeanRHLOC))
#check data distribution
gghistogram(loc_stats$Solar, bins = 5)
ggboxplot(loc_stats$Solar)
#Check lm model first
lm_Solar <- lm(Solar ~Elevation+Loc_type, data = loc_stats)
# Get summary and p values
summary(lm_Solar) #AIC delta <4, include interaction
# Plot
lm_solar_plot <- lm(Solar ~Elevation, data = loc_stats)
Mean_solar <- visualize(lm_solar_plot,  Solar ~ Elevation, plot="model")+
scale_color_manual(values = c("black"))+
theme_classic()+
#labs(title = NULL, y="Mean solar radiation (W/m2)", x=NULL)+
labs(title = NULL, y=expression(paste('Mean solar radiation' ~ " " ~ (W/m^{2}))), x=NULL)+
labs_pubr()+
theme(legend.position="null")
Mean_solar
#Check model fit, residuals etc.
autoplot(lm_Solar)+
theme_classic()
shapiro.test(residuals(lm_Solar))
#Check comparisons
summary(glht(lm_Solar, linfct = mcp(Loc_type = 'Tukey')))
#check data distribution
gghistogram(loc_stats$NO_Snow, bins = 50)
ggboxplot(loc_stats$NO_Snow)
#Check lm model first
lm_NO_Snow <- lm(NO_Snow ~ Elevation+Loc_type, data = loc_stats)
# Get summary and p values
summary(lm_NO_Snow)
# Plot
lm_plot_eSnow <- lm(NO_Snow ~ Elevation, data = loc_stats)
SnowDays_plot<- visualize(lm_plot_eSnow, NO_Snow ~ Elevation, plot="model")+
scale_color_manual(values = c("black"))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Days without snow (n. days)")), x=NULL)+
theme(legend.position="null")
SnowDays_plot
#Check model fit, residuals etc.
autoplot(lm_NO_Snow)+
theme_classic()
shapiro.test(residuals(lm_NO_Snow))
plot_micro <- ggarrange(MeanTemp_plot, SnowDays_plot, Mean_solar, Mean_humid, nrow = 2, ncol = 2, labels = NULL,
common.legend = TRUE, legend = "none", font.label = list(size=13))
plot_micro
ggsave("plot_micro_final.pdf", plot=plot_micro, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=20, dpi=300)
ggsave("plot_micro_final.pdf", plot=plot_micro, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=20, dpi=300)
ggsave("plot_microfinal.svg", plot=plot_micro, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=20, dpi=300)
ggsave("plot_micro_final.pdf", plot=plot_micro, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=20, dpi=300)
ggsave("plot_microfinal.svg", plot=plot_micro, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=20, dpi=300)
ggsave("plot_micro_final.png", plot=plot_micro, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=20, dpi=300, bg="white")
#check data distribution
gghistogram(res_ecto_stats$egg_dev, bins = 15)+
theme_pubclean()
ggboxplot(res_ecto_stats$egg_dev)+
theme_pubclean()+
labs(y=NULL, x=NULL)
#Check lm model first
lm_eggDev <- lm(egg_dev ~ Elevation+Species+Loc_type, data = res_ecto_stats)
lm_eggDev_int <- lm(egg_dev ~ Elevation*Species+Loc_type, data = res_ecto_stats)
lm_eggDev_int2<- lm(egg_dev ~ Elevation*Loc_type+Species, data = res_ecto_stats)
lm_eggDev_int3<- lm(egg_dev ~ Elevation+Loc_type*Species, data = res_ecto_stats)
compare.fits(egg_dev ~Elevation | Species+
Loc_type, data = res_ecto_stats, lm_eggDev, lm_eggDev_int)
compare.fits(egg_dev ~Elevation | Species+
Loc_type, data = res_ecto_stats, lm_eggDev, lm_eggDev_int2)
compare.fits(egg_dev ~Elevation | Species+
Loc_type, data = res_ecto_stats, lm_eggDev, lm_eggDev_int3)
AIC(lm_eggDev, lm_eggDev_int, lm_eggDev_int2, lm_eggDev_int3)
anova(lm_eggDev, lm_eggDev_int, lm_eggDev_int2, lm_eggDev_int3)
summary(lm_eggDev) ## NO SIGNIFICANT INTERACTIONS
#summary(lm_eggDev_int)
#summary(lm_eggDev_int2)
#summary(lm_eggDev_int3)
# Get summary and p values
visualize(lm_eggDev)
EggDev_plot <- visualize(lm_eggDev, egg_dev~Elevation+Loc_type |Species, plot="model")+
scale_color_manual(values = c("firebrick", "gold", "navyblue"))+
scale_shape_manual(values =c(19, 19, 19))+
scale_linetype_manual(values =c(1, 1, 1))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Egg development time (days)")), x=NULL)+
theme(
strip.text = element_text(face = "italic"),
axis.text=element_text(size=11),
axis.title=element_text(size=12,face="bold"))+
facet_wrap(~Species)
EggDev_plot
#Check model fit, residuals etc.
autoplot(lm_eggDev)+
theme_classic()
shapiro.test(residuals(lm_eggDev))
#Check comparisons
summary(glht(lm_eggDev, linfct = mcp(Loc_type = 'Tukey')))
#check data
gghistogram(res_ecto_stats$LifeSpan, bins = 4)
ggboxplot(res_ecto_stats$LifeSpan)
#Check lm model first
lm_Lifespan <- lm(LifeSpan ~ Elevation + Species+ Loc_type, data = res_ecto_stats)
lm_Lifespan_int <- lm(LifeSpan ~ Elevation*Species+Loc_type, data = res_ecto_stats)
lm_Lifespan_int2<- lm(LifeSpan ~ Elevation*Loc_type+Species, data = res_ecto_stats)
lm_Lifespan_int3<- lm(LifeSpan ~ Elevation+Loc_type*Species, data = res_ecto_stats)
compare.fits(LifeSpan ~Elevation | Species+Loc_type,
data = res_ecto_stats, lm_Lifespan, lm_Lifespan_int)
compare.fits(LifeSpan ~Elevation | Species+Loc_type,
data = res_ecto_stats, lm_Lifespan, lm_Lifespan_int2)
compare.fits(LifeSpan ~Elevation | Species+Loc_type,
data = res_ecto_stats, lm_Lifespan, lm_Lifespan_int3)
AIC(lm_Lifespan, lm_Lifespan_int, lm_Lifespan_int2, lm_Lifespan_int3)
anova(lm_Lifespan, lm_Lifespan_int, lm_Lifespan_int2, lm_Lifespan_int3)
summary(lm_Lifespan) ## NO SIGNIFICANT INTERACTIONS, CHECKED MODELS BY AIC AND COMPARED FITS
#summary(lm_Lifespan_int)
#summary(lm_Lifespan_int2)
#summary(lm_Lifespan_int3)
# Get summary and p values
visualize(lm_Lifespan_int2)
Lifespan_plot <-   visualize(lm_Lifespan, LifeSpan~Elevation + Loc_type|Species, plot="model")+
scale_color_manual(values = c("firebrick", "gold", "navyblue"))+
scale_shape_manual(values =c(19, 19, 19))+
scale_linetype_manual(values =c(1, 1, 1))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Lifespan (years)")), x=NULL)+
theme(
strip.text = element_text(face = "italic"),
axis.text=element_text(size=11),
axis.title=element_text(size=12,face="bold"))+
facet_wrap(~Species)
Lifespan_plot
#Check model fit, residuals etc.
autoplot(lm_Lifespan_int2)+
theme_classic()
shapiro.test(residuals(lm_Lifespan_int2))
#Check comparisons
summary(glht(lm_Lifespan, linfct = mcp(Loc_type = 'Tukey')))
#check data
gghistogram(res_ecto_stats$Years_repro, bins = 8)
ggboxplot(res_ecto_stats$Years_repro)
#Check lm model first
lm_YearsRepro_noLoc <- lm(Years_repro ~ Elevation + Species, data = res_ecto_stats)
lm_YearsRepro <- lm(Years_repro ~ Elevation + Species + Loc_type, data = res_ecto_stats)
lm_YearsRepro_int <- lm(Years_repro ~ Elevation*Species+Loc_type, data = res_ecto_stats)
lm_YearsRepro_int2<- lm(Years_repro ~ Elevation*Loc_type+Species, data = res_ecto_stats)
lm_YearsRepro_int3<- lm(Years_repro ~ Elevation+Loc_type*Species, data = res_ecto_stats)
compare.fits(Years_repro ~Elevation | Species+Loc_type,
data = res_ecto_stats, lm_YearsRepro, lm_YearsRepro_int)
compare.fits(Years_repro ~Elevation | Species+Loc_type,
data = res_ecto_stats, lm_YearsRepro, lm_YearsRepro_int2)
compare.fits(Years_repro ~Elevation | Species+Loc_type,
data = res_ecto_stats, lm_YearsRepro, lm_YearsRepro_int3)
AIC(lm_YearsRepro, lm_YearsRepro_int, lm_YearsRepro_int2, lm_YearsRepro_int3, lm_YearsRepro_noLoc)
anova(lm_YearsRepro_noLoc, lm_YearsRepro, lm_YearsRepro_int, lm_YearsRepro_int2, lm_YearsRepro_int3)
summary(lm_YearsRepro_noLoc) ## OPT FOR SIMPLER MODEL
#summary(lm_YearsRepro_int)
#summary(lm_YearsRepro_int2)
#summary(lm_YearsRepro_int3)
# Get summary and p values
visualize(lm_YearsRepro_noLoc)
YearsRepro_plot <-  visualize(lm_YearsRepro_noLoc, Years_repro~Elevation | Species, plot="model")+
scale_color_manual(values = c("black"))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Years reproducing (years)")), x=NULL)+
theme(strip.background = element_blank(),
strip.text.x = element_blank(),
axis.text=element_text(size=11),
axis.title=element_text(size=12,face="bold"))+
facet_wrap(~Species)
YearsRepro_plot
#Check model fit, residuals etc.
autoplot(lm_YearsRepro)+
theme_classic()
shapiro.test(residuals(lm_YearsRepro))
#check data
gghistogram(res_ecto_stats$Bask_year, bins = 8)
ggboxplot(res_ecto_stats$Bask_year)
#Check lm model first
lm_BaskYear <- lm(Bask_year ~ Elevation + Species + Loc_type, data = res_ecto_stats)
lm_BaskYear_int <- lm(Bask_year ~ Elevation*Species+Loc_type, data = res_ecto_stats)
lm_BaskYear_int2<- lm(Bask_year ~ Elevation*Loc_type+Species, data = res_ecto_stats)
lm_BaskYear_int3<- lm(Bask_year ~ Elevation+Loc_type*Species, data = res_ecto_stats)
compare.fits(Bask_year ~Elevation | Species+Loc_type,
data = res_ecto_stats, lm_BaskYear, lm_BaskYear_int)
compare.fits(Bask_year ~Elevation | Species+Loc_type,
data = res_ecto_stats, lm_BaskYear, lm_BaskYear_int2)
compare.fits(Bask_year ~Elevation | Species+Loc_type,
data = res_ecto_stats, lm_BaskYear, lm_BaskYear_int3)
AIC(lm_BaskYear, lm_BaskYear_int, lm_BaskYear_int2, lm_BaskYear_int3)
anova(lm_BaskYear, lm_BaskYear_int, lm_BaskYear_int2, lm_BaskYear_int3)
summary(lm_BaskYear) ## NO SIGNIFICANT INTERACTIONS
#summary(lm_BaskYear_int)
#summary(lm_BaskYear_int2)
#summary(lm_BaskYear_int3)
# Get summary and p values
visualize(lm_BaskYear)
Basking_plot <- visualize(lm_BaskYear, Bask_year~Elevation + Loc_type|Species, plot="model")+
scale_color_manual(values = c("firebrick", "gold", "navyblue"))+
scale_shape_manual(values =c(19, 19, 19))+
scale_linetype_manual(values =c(1, 1, 1))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Mean yearly basking time (hours)")), x=NULL)+
theme(strip.background = element_blank(),
strip.text.x = element_blank(),
axis.text=element_text(size=11),
axis.title=element_text(size=12,face="bold"))+
facet_wrap(~Species)
Basking_plot
#Check model fit, residuals etc.
autoplot(lm_BaskYear)+
theme_classic()
shapiro.test(residuals(lm_BaskYear))
#Check comparisons
summary(glht(lm_BaskYear, linfct = mcp(Loc_type = 'Tukey')))
#check data
gghistogram(res_ecto_stats$Forage_year, bins = 8)
ggboxplot(res_ecto_stats$Forage_year)
#Check lm model first
lm_ForageYear <- lm(Forage_year ~ Elevation + Species + Loc_type, data = res_ecto_stats)
lm_ForageYear_int <- lm(Forage_year ~ Elevation*Species+Loc_type, data = res_ecto_stats)
lm_ForageYear_int2<- lm(Forage_year ~ Elevation*Loc_type+Species, data = res_ecto_stats)
lm_ForageYear_int3<- lm(Forage_year ~ Elevation+Loc_type*Species, data = res_ecto_stats)
compare.fits(Forage_year ~Elevation | Species+Loc_type,
data = res_ecto_stats, lm_ForageYear, lm_ForageYear_int)
compare.fits(Forage_year ~Elevation | Species+Loc_type,
data = res_ecto_stats, lm_ForageYear, lm_ForageYear_int2)
compare.fits(Forage_year ~Elevation | Species+Loc_type,
data = res_ecto_stats, lm_ForageYear, lm_ForageYear_int3)
AIC(lm_ForageYear, lm_ForageYear_int, lm_ForageYear_int2, lm_ForageYear_int3)
anova(lm_ForageYear, lm_ForageYear_int, lm_ForageYear_int2, lm_ForageYear_int3)
summary(lm_ForageYear) ## NO SIGNIFICANT INTERACTION
#summary(lm_ForageYear_int)
#summary(lm_ForageYear_int2)
#summary(lm_ForageYear_int3)
# Plot
visualize(lm_ForageYear)
Forage_plot <-  visualize(lm_ForageYear, Forage_year~Elevation + Loc_type|Species, plot="model")+
scale_color_manual(values = c("firebrick", "gold", "navyblue"))+
scale_shape_manual(values =c(19, 19, 19))+
scale_linetype_manual(values =c(1, 1, 1))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Mean yearly foraging time (hours")), x="Elevation (m)")+
theme(strip.background = element_blank(),
strip.text.x = element_blank(),
axis.text=element_text(size=11),
axis.title=element_text(size=12,face="bold"))+
facet_wrap(~Species)
Forage_plot
#Check model fit, residuals etc.
autoplot(lm_ForageYear)+
theme_classic()
shapiro.test(residuals(lm_ForageYear))
#Check comparisons
summary(glht(lm_ForageYear, linfct = mcp(Loc_type = 'Tukey')))
#check data distribution
gghistogram(res_ecto_stats$Fecundity_year, bins = 15)
ggboxplot(res_ecto_stats$Fecundity_year)
#Check lm model first
lm_FecundityYear <- lm(Fecundity_year ~Elevation+ Species+Loc_type, data = res_ecto_stats)
lm_FecundityYear_int <- lm(Fecundity_year ~ Elevation*Species+Loc_type, data = res_ecto_stats)
lm_FecundityYear_int2<- lm(Fecundity_year ~Elevation*Loc_type+Species, data = res_ecto_stats)
lm_FecundityYear_int3<- lm(Fecundity_year ~Elevation+Loc_type*Species, data = res_ecto_stats)
compare.fits(Fecundity_year ~Elevation | Species+Loc_type,
data = res_ecto_stats, lm_FecundityYear, lm_FecundityYear_int)
compare.fits(Fecundity_year ~Elevation | Species+Loc_type,
data = res_ecto_stats, lm_FecundityYear, lm_FecundityYear_int2)
compare.fits(Fecundity_year ~Elevation | Species+Loc_type,
data = res_ecto_stats, lm_FecundityYear, lm_FecundityYear_int3)
AIC(lm_FecundityYear, lm_FecundityYear_int, lm_FecundityYear_int2, lm_FecundityYear_int3)
anova(lm_FecundityYear, lm_FecundityYear_int, lm_FecundityYear_int2, lm_FecundityYear_int3)
#summary(lm_FecundityYear)
summary(lm_FecundityYear_int) ## significant interaction
#summary(lm_FecundityYear_int2)
#summary(lm_FecundityYear_int3)
# Plot
visualize(lm_FecundityYear_int)
Fecundity_plot <-  visualize(lm_FecundityYear_int, Fecundity_year~Elevation + Loc_type|Species, plot="model")+
scale_color_manual(values = c("firebrick", "gold", "navyblue"))+
scale_shape_manual(values =c(19, 19, 19))+
scale_linetype_manual(values =c(1, 1, 1))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Yearly fecundity (n. offspring)")), x="Elevation (m)")+
theme(strip.background = element_blank(),
strip.text.x = element_blank(),
axis.text=element_text(size=11),
axis.title=element_text(size=12,face="bold"))+
facet_wrap(~Species)
Fecundity_plot
#Check model fit, residuals etc.
autoplot(lm_FecundityYear_int)+
theme_classic()
shapiro.test(residuals(lm_FecundityYear_int))
#Check comparisons
summary(glht(lm_FecundityYear_int, linfct = mcp(Loc_type = 'Tukey')))
plot_ecto <- ggarrange(EggDev_plot, Lifespan_plot, YearsRepro_plot, Basking_plot, Forage_plot, Fecundity_plot, nrow = 3, ncol = 2, labels = NULL, common.legend = FALSE, legend = "none", font.label = list(size = 13, color = "black", face = "bold"))
plot_ecto
ggsave("plot_ecto_final.pdf", plot=plot_ecto, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=20, dpi=300)
ggsave("plot_ecto_final.svg", plot=plot_ecto, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=20, dpi=300)
ggsave("plot_ecto_final.png", plot=plot_ecto, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=20, dpi=300, bg="white")
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(message=FALSE)
knitr::opts_chunk$set(warning=FALSE)
knitr::opts_chunk$set(tidy=TRUE)
#check data
gghistogram(res_ecto_stats$Forage_year, bins = 8)
using<-function(...) {
libs<-unlist(list(...))
req<-unlist(lapply(libs,require,character.only=TRUE))
need<-libs[req==FALSE]
if(length(need)>0){
install.packages(need)
lapply(need,require,character.only=TRUE)
}
}
using("dplyr", "ggplot2", "ggpubr", "rstatix", "NCmisc", "car", "lme4", "DHARMa", "emmeans", "performance", "sjPlot", "rphylopic", "jpeg", "flexplot", "report", "broom", "ggfortify", "MASS", "jtools", "svglite",  "multcomp", "vegan", "showtext", "formatR")
#rm(list = ls())
#check data
gghistogram(res_ecto_stats$Forage_year, bins = 8)
ggboxplot(res_ecto_stats$Forage_year)
#Check lm model first
lm_ForageYear <- lm(Forage_year ~ Elevation + Species + Loc_type, data = res_ecto_stats)
lm_ForageYear_int <- lm(Forage_year ~ Elevation*Species+Loc_type, data = res_ecto_stats)
lm_ForageYear_int2<- lm(Forage_year ~ Elevation*Loc_type+Species, data = res_ecto_stats)
lm_ForageYear_int3<- lm(Forage_year ~ Elevation+Loc_type*Species, data = res_ecto_stats)
compare.fits(Forage_year ~Elevation | Species+Loc_type,
data = res_ecto_stats, lm_ForageYear, lm_ForageYear_int)
compare.fits(Forage_year ~Elevation | Species+Loc_type,
data = res_ecto_stats, lm_ForageYear, lm_ForageYear_int2)
compare.fits(Forage_year ~Elevation | Species+Loc_type,
data = res_ecto_stats, lm_ForageYear, lm_ForageYear_int3)
AIC(lm_ForageYear, lm_ForageYear_int, lm_ForageYear_int2, lm_ForageYear_int3)
anova(lm_ForageYear, lm_ForageYear_int, lm_ForageYear_int2, lm_ForageYear_int3)
summary(lm_ForageYear) ## NO SIGNIFICANT INTERACTION
#summary(lm_ForageYear_int)
#summary(lm_ForageYear_int2)
#summary(lm_ForageYear_int3)
# Plot
visualize(lm_ForageYear)
Forage_plot <-  visualize(lm_ForageYear, Forage_year~Elevation + Loc_type|Species, plot="model")+
scale_color_manual(values = c("firebrick", "gold", "navyblue"))+
scale_shape_manual(values =c(19, 19, 19))+
scale_linetype_manual(values =c(1, 1, 1))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Mean yearly foraging time (hours)")), x="Elevation (m)")+
theme(strip.background = element_blank(),
strip.text.x = element_blank(),
axis.text=element_text(size=11),
axis.title=element_text(size=12,face="bold"))+
facet_wrap(~Species)
Forage_plot
#Check model fit, residuals etc.
autoplot(lm_ForageYear)+
theme_classic()
shapiro.test(residuals(lm_ForageYear))
#Check comparisons
summary(glht(lm_ForageYear, linfct = mcp(Loc_type = 'Tukey')))
plot_ecto <- ggarrange(EggDev_plot, Lifespan_plot, YearsRepro_plot, Basking_plot, Forage_plot, Fecundity_plot, nrow = 3, ncol = 2, labels = NULL, common.legend = FALSE, legend = "none", font.label = list(size = 13, color = "black", face = "bold"))
plot_ecto
ggsave("plot_ecto_final.pdf", plot=plot_ecto, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=20, dpi=300)
ggsave("plot_ecto_final.svg", plot=plot_ecto, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=20, dpi=300)
ggsave("plot_ecto_final.png", plot=plot_ecto, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=20, dpi=300, bg="white")
